package makotome.contact;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ListView;

public class smsPopListActivity extends Activity{
    ListView chatlist = null;

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.smspopmain);
            chatlist = (ListView) findViewById(R.id.chatlist);
            chatlist.setAdapter(new ChatAdapter(smsPopListActivity.this,getSmsInfo("256")));
    }
     
    public ArrayList<ChatEntity> getSmsInfo(String thread_id)  
    {  
    	ArrayList<ChatEntity> smslist = new ArrayList<ChatEntity>(); 
        String[] projection = new String[]  
        { "thread_id", "address", "person", "body", "date", "type","read" };  
        Uri uri = Uri.parse("content://sms/");
        ContentResolver cr = getContentResolver();            
          
        Cursor cursor = cr.query  
        (  
                uri,   
                projection,   
                "thread_id=?",  
                new String[] { thread_id } ,  
                "date asc"
        );  
          
        while (cursor.moveToNext())  
        {  
        	ChatEntity chatEntity;
            String PhoneNum="";
            String SmsCont="";
            int phoneNumber = cursor.getColumnIndex("address");
            int smsContent = cursor.getColumnIndex("body");
            int type = cursor.getColumnIndex("type");
            PhoneNum=cursor.getString(phoneNumber);
            SmsCont = cursor.getString(smsContent);
            
            if(type == 1){
            	chatEntity = new ChatEntity(PhoneNum,SmsCont,R.layout.smspoplist);
            }else{
            	chatEntity = new ChatEntity(PhoneNum,SmsCont,R.layout.smspoplistb);
            }
            
            smslist.add(chatEntity);
        }
        
        return smslist;                  
    }

}
